﻿using Bigger.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Bigger.Study.ConsoleApp.Async
{
    public class LockSyncExample : IExample
    {
        private readonly static object LockObject = new object();
        public void Execute()
        {
            int count = 0;
            for (int i = 0; i < 10; i++)
            {
                Monitor.Enter(LockObject);
                try
                {
                    count++;
                }
                finally
                {
                    Monitor.Exit(LockObject);
                }
                ConsoleHelper.WriteLineYellow("执行" + i);
                Thread.Sleep(500);
            }
        }
    }
}
